package priv.conceit.study.book.lambda.chapter3;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * FlatMap
 *
 * stream替换值，然后将多个Stream链接为一个stream
 *
 * @author Conceit
 * @since 1.0.0, 2021/9/12
 */
@Data
@AllArgsConstructor
public class FlatMap {

    private Long age;
    private String name;

    public static void main(String[] args) {
        List<FlatMap> flatMaps=new ArrayList<>();
        flatMaps.add(new FlatMap(1L,"a-b"));
        flatMaps.add(new FlatMap(2L,"b-c"));
        flatMaps.add(new FlatMap(3L,"c-d"));
        flatMaps.add(new FlatMap(4L,"d-e"));
        flatMaps.add(new FlatMap(5L,"e-f"));

        flatMaps(flatMaps);
    }

    /**
     * flatMap(item-> Arrays.stream(item.name.split("-")))
     * 多个Stream链接为一个stream
     * @param flatMaps
     */
    public static void flatMaps(List<FlatMap> flatMaps){
        flatMaps.stream().flatMap(item-> Arrays.stream(item.name.split("-"))).collect(Collectors.toList()).forEach(System.out::println);
    }


}
